<?php

namespace App\Repository;


use App\User;

class UserRepository 
{
    /**
     * 根据openID获取用户信息
     * @param $openid
     * @return mixed
     */
    public static function getByOpenId($openid)
    {
        return User::where('openid', $openid)->first();
    }

    /**
     * 创建一个新用户
     * @param $openid
     * @return int|mixed
     */
    public static function newUser($openid)
    {
        $user = User::create([
            'openid'=>$openid,
            'nickname' => 'nickname',
            'email' => 'laravel@outlook.com',
            'password' => bcrypt('password'),
        ]);
        return $user->id;
    }

    /**
     * 根据ID获取用户数据
     * @param $id
     * @return mixed
     */
    public function getUserById($id)
    {
        return User::find($id);
    }
}